#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;

typedef struct Node {
	int x,y,z,step;
}node;
int L,R,C,sx,sy,sz,ox,oy,oz,flag;
int next_s[6][3]={{0,1,0},{1,0,0},{0,-1,0},{-1,0,0},{0,0,1},{0,0,-1}};
int book[35][35][35];
char map[35][35][35];
void bfs(int x,int y,int z){
	queue<node> M;
	node a;
	a.x=x;
	a.y=y;
	a.z=z;
	a.step=0;
	book[x][y][z]=1;
	M.push(a);
	while(!M.empty()){
		node A=M.front();
                M.pop(); 
		if(A.x==ox&&A.y==oy&&A.z==oz){
			printf("Escaped in %d minute(s).\n",A.step);
            flag=1;			
			break;
		}
		for(int k=0;k<6;k++){
		int tx=A.x+next_s[k][0];
		int ty=A.y+next_s[k][1];
		int tz=A.z+next_s[k][2];
		if(tx<0||ty<0||tz<0||tx>=L||ty>=R||tz>=C||map[tx][ty][tz]=='#'||book[tx][ty][tz]==1)
		continue;
		node kk;
		book[tx][ty][tz]=1;
		kk.x=tx;
		kk.y=ty;
		kk.z=tz;
		kk.step=A.step+1;
		M.push(kk);
		}
	}
}

int main(){
	while(~scanf("%d %d %d",&L,&R,&C)){
		if(L==0&&R==0&&C==0)
		break;
		flag=0;
		memset(book,0,sizeof(book));		
		for(int i=0;i<L;i++)
		for(int j=0;j<R;j++){
			scanf("%s",map[i][j]);
			for(int k=0;k<C;k++){
				if(map[i][j][k]=='S'){
					sx=i;sy=j;sz=k;		
					}
				if(map[i][j][k]=='E'){
					ox=i;oy=j;oz=k;
				}
			}
		}
		bfs(sx,sy,sz);
		if(flag==0)
		printf("Trapped!\n");
	}
}